package com.atguigu.demo.servlet;

import com.alibaba.fastjson.JSON;
import com.atguigu.demo.entity.Result;
import com.atguigu.demo.service.api.TigerService;
import com.atguigu.demo.service.impl.TigerServiceImpl;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;

@WebServlet(name = "TigerServletRemove", value = "/TigerServletRemove")
public class TigerServletRemove extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 1、创建 Service 对象
        TigerService tigerService = new TigerServiceImpl();

        // 2、从请求参数中获取 id 值
        String tigerId = request.getParameter("tigerId");

        // 3、调用 Service 方法执行删除
        tigerService.removeById(tigerId);

        // 4、返回响应
        response.getWriter().write(JSON.toJSONString(Result.ok()));
    }
}
